<?php

namespace Joy\OAuth;

use Joy\OAuth\command\PublishCommand;
use Joy\OAuth\command\KeysCommand;
use think\facade\Route;
use think\Service;

/**
 * JoyAuth service
 */
class JoyAuthService extends Service {
        /**
     * Register service.
     *
     * @return void
     */
    public function register()
    {
        // 注册数据迁移服务
        $this->app->register(\think\migration\Service::class);
        
        // 绑定 Casbin决策器
        // $this->app->bind('enforcer', function () {
        //     $default = $this->app->config->get('tauthz.default');

        //     $config = $this->app->config->get('tauthz.enforcers.'.$default);
        //     $adapter = $config['adapter'];

        //     $configType = $config['model']['config_type'];

        //     $model = new Model();
        //     if ('file' == $configType) {
        //         $model->loadModel($config['model']['config_file_path']);
        //     } elseif ('text' == $configType) {
        //         $model->loadModel($config['model']['config_text']);
        //     }

        //     return new Enforcer($model, app($adapter), $this->app->config->get('tauthz.log.enabled', false));
        // });
    }

    /**
     * Boot function.
     *
     * @return void
     */
    public function boot()
    {
        // 注册命令
        $this->commands(['oauth:publish' => PublishCommand::class]);
        $this->commands(['oauth:keys' => KeysCommand::class]);
    }
}